03. TF DenseFeatures Walkthrough

TF DenseFeatures Walkthrough

ND320 AIHCND C01 L04 A03 Build A Tensorflow Regression Model With DenseFeatures

Key Points

Tensorflow DenseFeatures Layer

Tensorflow provides the DenseFeatures layer as a way to combine some of the Tensorflow feature columns we learned earlier into a dense input tensor to your model. For this example, we use the Sequential API but you could use the Functional API as well with some adjustments. Hopefully, the Tensorflow Keras modeling functions should be familiar to you and for the walkthrough, we again used the architecture from the Tensorflow regression tutorial.

One key thing to note is that you can only use some Tensorflow Feature Column types with DenseFeatures so it is worth checking. At the time of writing this course, here are the features that you can use.

Below I will walk through the simple steps to use the DenseFeatures layer.

  • First, combine all of your Tensorflow feature columns into a list that can be passed to the DenseFeatures layer. Please note that this is not the column name but the Tensorflow feature column metadata that you will get when you create a Tensorflow feature.
feature_columns = tf_categorical_feature_list + tf_numerical_feature_list
dense_feature_layer = tf.keras.layers.DenseFeatures(feature_columns)
  • Next, we simply add this 'dense_feature_layer' as the first layer to the model and this will handle the combining of feature inputs to the model.
    model = tf.keras.Sequential([
    **dense_feature_layer**,
    tf.keras.layers.Dense(64, activation='relu')
   ... additional layers

Code

If you need a code on the https://github.com/udacity.